package com.fa4j.system.account.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fa4j.common.data.model.Base;
import com.fa4j.common.web.model.AppType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * 权限日志
 *
 * @since 2025-07-15 17:42:53
 */
@Data
@TableName(value = "t_sys_account_log", autoResultMap = true)
@Schema(description = "权限日志")
public class AccountLog extends Base {

    @Schema(description = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @Schema(description = "应用类型")
    private AppType appType;

    @TableField(exist = false)
    @Schema(description = "应用名称")
    private String appName;

    @Schema(description = "账号ID")
    private Long accountId;

    @TableField(exist = false)
    @Schema(description = "账号名称")
    private String accountName;

    @Schema(description = "模块名称")
    private String moduleName;

    @Schema(description = "资源名称")
    private String resourceName;

    @Schema(description = "资源方法")
    private String resourceMethod;

    @Schema(description = "资源路径")
    private String resourcePath;

    @Schema(description = "客户端IP")
    private String clientIp;

    @Schema(description = "客户端UA")
    private String clientUserAgent;

    @Schema(description = "是否成功")
    private Boolean success;

    @Schema(description = "请求参数")
    private String params;

    @Schema(description = "响应结果")
    private String result;

    @Schema(description = "开始时间")
    private LocalDateTime startTime;

    @Schema(description = "结束时间")
    private LocalDateTime endTime;

    @Schema(description = "操作人ID")
    private Long operatorId;

    @Schema(description = "耗时")
    public long getCost() {
        return Duration.between(startTime, endTime).toMillis();
    }


}
